﻿using System;

namespace ConsoleApp1
{
    class Program
    {
        public int pivotIndex(int[] nums) {
            int totalSum = 0;
            int forwardSum = 0;
            int index = 0;
            foreach(int val in nums) {
                totalSum += val;
            }
            foreach(int num in nums)
            {
                if ((totalSum - num) % 2 == 0 && (totalSum - num) / 2 == forwardSum) return index;
                forwardSum += num;
                index++;
            }
            return -1;
        }
        static void Main(string[] args)
        {
            Program program = new Program();
            //定义测试集
            int[] nums = new int[] { 1, 7, 3, 6, 5, 6 };
            Console.Write("数组的中心索引为：");
            Console.WriteLine(program.pivotIndex(nums));
        }
    }
}
